// components/productList/index.js
import api from "../../config/api";
import request from "../../utils/request";
const app = getApp()

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        // 商品列表
        list: {
            type: Array,
            value: [],
        },
        // 列表是否加载完成
        isDone: {
            type: Boolean,
            value: false,
        },
        // 是否展示空状态
        showEmpty: {
            type: Boolean,
            value: true,
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        standardTip: { 10: '全新', 20: '轻微使用痕迹', 30: '9.5新', 40: '9成新', 50: '8成新', 60: '7成新', 70: '6成新', 80: '严重使用痕迹', 90: '全新仅拆封' }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        // 跳转到小鹿闲置小程序
        jumpIdleApplet(e) {
            let id = e.currentTarget.dataset.id
            if (app.isLogin()) {
                const {
                    loadMiniProgram
                } = this.data
                if (loadMiniProgram) return
                this.setData({
                    loadMiniProgram: true,
                })
                this.miniGoodsDataLogSave(2)
                //不是代代回收用户，跳转代代回收小程序完成注册
                wx.navigateToMiniProgram({
                    appId: 'wx5a2f319913b5b3e9',
                    path: `pages/goodsDetails/goodsDetails?source=QD000001&goodsId=${id}`,
                    envVersion: 'trial',
                    success: () => {
                        console.log('跳转成功')
                        this.miniGoodsDataLogSave(3)
                    },
                    fail: (error) => {
                        console.log('跳转失败', error)
                        if (error?.errMsg !== 'navigateToMiniProgram:fail cancel') {
                            wx.showToast({
                                title: '跳转失败，请重试',
                                icon: 'none',
                            })
                        }
                    },
                    complete: () => {
                        this.setData({
                            loadMiniProgram: false,
                        })
                    },
                })
            } else {
                app.login()
            }
        },
        // 小鹿闲置小程序跳转弹窗数据统计
        miniGoodsDataLogSave(type) {
            request.post(api.miniGoodsDataLogSave, {
                type
            }, {
                loading: false
            })
        },
    }
})